package com.cq.hd.app.mq;

import com.alibaba.fastjson.JSON;
import com.cq.hd.common.constant.RabbitMqConstant;
import com.cq.hd.common.entity.mq.UserLoginRecordMsg;
import com.cq.hd.common.utils.GenerateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class UserLoginRecordMsgProvider {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMsg(UserLoginRecordMsg userLoginRecordMsg) {
        Map<String, Object> map = new HashMap<>(2);
        map.put("messageId", GenerateUtil.getMsg("user-login-record"));
        map.put("messageData", JSON.toJSONString(userLoginRecordMsg));
        log.info("发送用户/商家登录消息：" + map.toString());

//        CorrelationData correlationData = new CorrelationData();
//        correlationData.setId(msgId);
//        rabbitTemplate.convertAndSend(RabbitMqConstant.BUSINESS_ENTER_EXCHANGE_DIRECT, RabbitMqConstant.BUSINESS_ENTER_ROUTING_KEY, map, correlationData);

        rabbitTemplate.convertAndSend(RabbitMqConstant.USER_LOGIN_RECORD_EXCHANGE_DIRECT, RabbitMqConstant.USER_LOGIN_RECORD_ROUTING_KEY, map);
    }

}
